package com.infodms.dms.dao.sales.salesInfoManage;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.common.Constant;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.dao.sales.ordermanage.reqquery.ReqQueryDao;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.businessUtil.GetVinUtil;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;
import com.infoservice.po3.core.PageQuery;

/**
 * @Title : SalesInfoQueryDAO.java
 * @Package: com.infodms.dms.dao.sales.salesInfoManage
 * @Description: 实销信息查询DAO
 * @date : 2010-6-30
 * @version: V1.0
 */
public class SalesInfoQueryDAO extends BaseDao {
	public static Logger logger = Logger.getLogger(SalesInfoQueryDAO.class);
	private static final SalesInfoQueryDAO dao = new SalesInfoQueryDAO();

	public static final SalesInfoQueryDAO getInstance() {
		return dao;
	}

	/**
	 * @Title : queryReportInfoList
	 * @Description: 实销信息查询结果展示
	 * @return : PageResult<Map<String,Object>>
	 * @throws
	 * @LastUpdate :2010-6-30
	 */
	public static PageResult<Map<String, Object>> queryReportInfoList(Map<String,String> map,int pageSize, int curPage) {
		String customer_type = (String) map.get("customer_type"); 	// 客户类型
		String customer_name = (String) map.get("customer_name"); 	// 客户名称
		String vin = (String) map.get("vin"); 						// VIN
		String customer_phone = (String) map.get("customer_phone"); // 客户电话
		String materialCode = (String) map.get("materialCode"); 	// 选择物料组
		String is_fleet = (String) map.get("is_fleet"); 			// 是否集团客户
		String fleet_name = (String) map.get("fleet_name"); 		// 集团客户名称
		String contract_no = (String) map.get("contract_no"); 		// 集团客户合同
		String startDate = (String) map.get("startDate"); 			// 上报日期:开始
		String endDate = (String) map.get("endDate"); 				// 上报日期 ：截止
		String dealerCode = (String) map.get("dealerCode"); 		// 经销商代码
		String orgCode=(String)map.get("orgCode");					// 区域
		String areaId = (String)map.get("areaId");					// 业务范围
		String orgId = map.get("orgId") ;
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT XX.DEALER_CODE,\n");
		sql.append("XX.DEALER_SHORTNAME,\n");
		sql.append("XX.CTM_NAME,\n");
		sql.append("XX.CTM_TYPE,\n");
		sql.append("XX.IS_FLEET,\n");
		sql.append("XX.FLEET_NAME,\n");
		sql.append("XX.CONTRACT_NO, \n");
		sql.append("XX.MAIN_PHONE,\n");
		sql.append("XX.MATERIAL_CODE,\n");
		sql.append("XX.MATERIAL_NAME,\n");
		sql.append("XX.VIN,\n");
		sql.append("XX.CAR_CHARACTOR,\n");
		sql.append("XX.ENGINE_NO,\n");
		sql.append("XX.PRODUCT_DATE ,\n");
		sql.append("XX.SALES_DATE,\n");
		sql.append("XX.CTM_ID,\n");
		sql.append("XX.VEHICLE_ID,\n");
		sql.append("XX.ORG_NAME,\n");
		sql.append(" XX.REGION_NAME  FROM (\n");
		sql.append("SELECT TMD.DEALER_CODE, --经销商代码\n");
		sql.append("       TMD.DEALER_SHORTNAME, --经销商名称\n");  
		sql.append("       TMD.DEALER_ID, \n");  
		sql.append("       TTC.CTM_NAME, --客户名称\n");  
		sql.append("       TTC.CTM_TYPE, --客户类型\n");  
		sql.append("       TTS.IS_FLEET, --是否集团客户\n");  
		sql.append("       TF.FLEET_NAME, --集团客户名称\n");  
		sql.append("       TFC.CONTRACT_NO, --集团客户合同\n");  
		sql.append("       TTC.MAIN_PHONE, --主要联系电话\n");  
		sql.append("       M.MATERIAL_CODE, --物料代码\n");  
		sql.append("       M.MATERIAL_NAME, --物料名称\n");  
		sql.append("       TMV.VIN, --VIN\n"); 
		sql.append("TTS.CAR_CHARACTOR, --车辆性质\n");
		sql.append("       TMV.ENGINE_NO, --VIN\n"); 
		sql.append("	   TO_CHAR(TMV.PRODUCT_DATE, 'yyyy-MM-dd') PRODUCT_DATE ,\n");
		sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");  
		sql.append("       TTC.CTM_ID,\n");
		sql.append("       TMV.VEHICLE_ID,\n");
		sql.append("       VOD.ROOT_ORG_NAME ORG_NAME,VOD.REGION_NAME REGION_NAME \n");
		sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");  
		sql.append("       TM_DEALER              TMD,\n");  
		sql.append("       TT_CUSTOMER            TTC,\n");  
		sql.append("       TM_VEHICLE             TMV,\n");  
		sql.append("       TM_VHCL_MATERIAL       M,\n");  
		sql.append("       TM_FLEET               TF,\n");  
		sql.append("       TT_FLEET_CONTRACT      TFC,VW_ORG_DEALER VOD\n");  
		sql.append(" WHERE TTS.DEALER_ID = TMD.DEALER_ID\n");  
		sql.append("   AND VOD.DEALER_ID=TMD.DEALER_ID \n");
//		sql.append("   AND TC1.CODE_ID = TTC.CTM_TYPE \n");
//		sql.append("   AND TC2.CODE_ID = TTS.IS_FLEET");
		sql.append("   AND TTS.CTM_ID = TTC.CTM_ID\n");  
		sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");  
		sql.append("   AND TMV.MATERIAL_ID = M.MATERIAL_ID\n");  
		sql.append("   AND TTS.FLEET_ID = TF.FLEET_ID(+)\n");  
		sql.append("   AND TTS.IS_RETURN='"+Constant.IF_TYPE_NO+"'");
		sql.append("   AND TTS.CONTRACT_ID = TFC.CONTRACT_ID(+)\n");  
		if (!"".equals(customer_type)) {
			sql.append("   AND TTC.CTM_TYPE = "+customer_type+"\n");
		}
		if (!"".equals(customer_name)) {
			sql.append("   AND TTC.CTM_NAME LIKE '%"+customer_name.trim()+"%'\n");
		}
		if (!"".equals(vin)) {
			sql.append(GetVinUtil.getVins(vin, "TMV"));
		}
		if (!"".equals(customer_phone)) {
			sql.append("   AND TTC.MAIN_PHONE LIKE '%"+customer_phone.trim()+"%'\n");
		}
		if (null != materialCode && !"".equals(materialCode)) {
			String[] materialCodes = materialCode.split(",");
			if (null != materialCodes && materialCodes.length > 0) {
				StringBuffer buffer = new StringBuffer();
				for (int i = 0; i < materialCodes.length; i++) {
					buffer.append("'").append(materialCodes[i]).append("'").append(",");
				}
				buffer = buffer.deleteCharAt(buffer.length() - 1);
				sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID\n");
				sql.append("FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))\n");
				sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                            WHERE G.GROUP_CODE IN ("+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                              FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                             WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
			}
		}
		if (!"".equals(is_fleet)) {
			sql.append("   AND TTS.IS_FLEET = "+is_fleet+"\n");
		}
		if (!"".equals(fleet_name)) {
			sql.append("   AND TF.FLEET_NAME LIKE '%"+fleet_name+"%'\n");
		}
		if (!"".equals(contract_no)) {
			sql.append("   AND TFC.CONTRACT_NO LIKE '%"+contract_no+"%'\n");
		}
		if (null != startDate && !"".equals(startDate)) {
			sql.append("   AND TTS.SALES_DATE >= TO_DATE('"+ startDate+" 00:00:00','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != endDate && !"".equals(endDate)) {
			sql.append("   AND TTS.SALES_DATE  <= TO_DATE('"+endDate+" 23:59:59','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != dealerCode && !"".equals(dealerCode)) {
			String[] array = dealerCode.split(",");
			sql.append("   AND TMD.DEALER_CODE IN(\n");
			for (int i = 0; i < array.length; i++) {
				sql.append("'" + array[i] + "'");
				if (i != array.length - 1) {
					sql.append(",");
				}
			}
			sql.append(")\n");
		}
		if (!"".equals(orgCode)) {
			sql.append("AND TMD.DEALER_ID IN\n");
			sql.append("       (SELECT TD.DEALER_ID\n");  
			sql.append("          FROM TM_DEALER TD\n");  
			sql.append("         START WITH TD.DEALER_ID IN\n");  
			sql.append("                    (SELECT TDOR.DEALER_ID\n");  
			sql.append("                       FROM TM_DEALER_ORG_RELATION TDOR\n");  
			sql.append("                      WHERE TDOR.ORG_ID IN\n");  
			sql.append("                            (SELECT ORG_ID\n");  
			sql.append("                               FROM TM_ORG ORG\n");  
			sql.append("                              WHERE ORG.STATUS = "+Constant.STATUS_ENABLE+"\n");  
			sql.append("                              START WITH ORG_CODE = '"+orgCode+"'\n");  
			sql.append("                             CONNECT BY PRIOR ORG.ORG_ID = ORG.PARENT_ORG_ID))\n");  
			sql.append("        CONNECT BY PRIOR TD.DEALER_ID = TD.PARENT_DEALER_D)\n");

		}
		
		if(!CommonUtils.isNullString(orgId)) {
			sql.append(ReqQueryDao.limitOrg("TMD", "dealer_id", orgId)) ;
		}
		
		sql.append("   AND TMV.AREA_ID IN ("+areaId+")\n");  
		sql.append("   AND TMV.LIFE_CYCLE = "+Constant.VEHICLE_LIFE_04+"\n");  
		sql.append(" UNION \n");
		sql.append("SELECT TMD.DEALER_CODE, --经销商代码\n");
		sql.append("       TMD.DEALER_SHORTNAME, --经销商名称\n"); 
		sql.append("       TMD.DEALER_ID, \n");  
		sql.append("       TTC.CTM_NAME, --客户名称\n");  
		sql.append("       TTC.CTM_TYPE, --客户类型\n");  
		sql.append("       TTS.IS_FLEET, --是否集团客户\n");  
		sql.append("       TCP.PACT_NAME FLEET_NAME, --集团客户名称\n");  
		sql.append("       TCP.PACT_NAME CONTRACT_NO, --集团客户合同\n");  
		sql.append("       TTC.MAIN_PHONE, --主要联系电话\n");  
		sql.append("       M.MATERIAL_CODE, --物料代码\n");  
		sql.append("       M.MATERIAL_NAME, --物料名称\n");  
		sql.append("       TMV.VIN, --VIN\n"); 
		sql.append("TTS.CAR_CHARACTOR, --车辆性质\n");
		sql.append("       TMV.ENGINE_NO, --VIN\n"); 
		sql.append("	   TO_CHAR(TMV.PRODUCT_DATE, 'yyyy-MM-dd') PRODUCT_DATE ,\n");
		sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");  
		sql.append("       TTC.CTM_ID,\n");
		sql.append("       TMV.VEHICLE_ID,\n");
		sql.append("       VOD.ROOT_ORG_NAME ORG_NAME,VOD.REGION_NAME REGION_NAME \n");
		sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");  
		sql.append("       TM_DEALER              TMD,\n");  
		sql.append("       TT_CUSTOMER            TTC,\n");  
		sql.append("       TM_VEHICLE             TMV,\n");  
		sql.append("       TM_VHCL_MATERIAL       M,\n");  
		sql.append("       TM_FLEET               TF,\n");  
		sql.append("       TT_FLEET_CONTRACT      TFC,TM_COMPANY_PACT TCP,VW_ORG_DEALER VOD\n");  
		sql.append(" WHERE TTS.DEALER_ID = TMD.DEALER_ID\n");  
		sql.append("   AND VOD.DEALER_ID=TMD.DEALER_ID \n");
		sql.append("   AND TTS.CTM_ID = TTC.CTM_ID\n");  
		sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");  
		sql.append("   AND TMV.MATERIAL_ID = M.MATERIAL_ID\n");  
		sql.append("   AND TTS.FLEET_ID = TCP.PACT_ID\n");  
		sql.append("   AND TTS.IS_RETURN='"+Constant.IF_TYPE_NO+"'");
		sql.append("   AND TTS.CONTRACT_ID = TFC.CONTRACT_ID(+)\n");  
		if (!"".equals(customer_type)) {
			sql.append("   AND TTC.CTM_TYPE = "+customer_type+"\n");
		}
		if (!"".equals(customer_name)) {
			sql.append("   AND TTC.CTM_NAME LIKE '%"+customer_name.trim()+"%'\n");
		}
		if (!"".equals(vin)) {
			sql.append(GetVinUtil.getVins(vin, "TMV"));
		}
		if (!"".equals(customer_phone)) {
			sql.append("   AND TTC.MAIN_PHONE LIKE '%"+customer_phone.trim()+"%'\n");
		}
		if (null != materialCode && !"".equals(materialCode)) {
			String[] materialCodes = materialCode.split(",");
			if (null != materialCodes && materialCodes.length > 0) {
				StringBuffer buffer = new StringBuffer();
				for (int i = 0; i < materialCodes.length; i++) {
					buffer.append("'").append(materialCodes[i]).append("'").append(",");
				}
				buffer = buffer.deleteCharAt(buffer.length() - 1);
				sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID\n");
				sql.append("FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))\n");
				sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                            WHERE G.GROUP_CODE IN ("+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                              FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                             WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
			}
		}
		if (!"".equals(is_fleet)) {
			sql.append("   AND TTS.IS_FLEET = "+is_fleet+"\n");
		}
		if (!"".equals(fleet_name)) {
			sql.append("   AND TF.FLEET_NAME LIKE '%"+fleet_name+"%'\n");
		}
		if (!"".equals(contract_no)) {
			sql.append("   AND TFC.CONTRACT_NO LIKE '%"+contract_no+"%'\n");
		}
		if (null != startDate && !"".equals(startDate)) {
			sql.append("   AND TTS.SALES_DATE >= TO_DATE('"+ startDate+" 00:00:00','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != endDate && !"".equals(endDate)) {
			sql.append("   AND TTS.SALES_DATE  <= TO_DATE('"+endDate+" 23:59:59','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != dealerCode && !"".equals(dealerCode)) {
			String[] array = dealerCode.split(",");
			sql.append("   AND TMD.DEALER_CODE IN(\n");
			for (int i = 0; i < array.length; i++) {
				sql.append("'" + array[i] + "'");
				if (i != array.length - 1) {
					sql.append(",");
				}
			}
			sql.append(")\n");
		}
		if (!"".equals(orgCode)) {
			sql.append("AND TMD.DEALER_ID IN\n");
			sql.append("       (SELECT TD.DEALER_ID\n");  
			sql.append("          FROM TM_DEALER TD\n");  
			sql.append("         START WITH TD.DEALER_ID IN\n");  
			sql.append("                    (SELECT TDOR.DEALER_ID\n");  
			sql.append("                       FROM TM_DEALER_ORG_RELATION TDOR\n");  
			sql.append("                      WHERE TDOR.ORG_ID IN\n");  
			sql.append("                            (SELECT ORG_ID\n");  
			sql.append("                               FROM TM_ORG ORG\n");  
			sql.append("                              WHERE ORG.STATUS = "+Constant.STATUS_ENABLE+"\n");  
			sql.append("                              START WITH ORG_CODE = '"+orgCode+"'\n");  
			sql.append("                             CONNECT BY PRIOR ORG.ORG_ID = ORG.PARENT_ORG_ID))\n");  
			sql.append("        CONNECT BY PRIOR TD.DEALER_ID = TD.PARENT_DEALER_D)\n");

		}
		if(!CommonUtils.isNullString(orgId)) {
			sql.append(ReqQueryDao.limitOrg("TMD", "dealer_id", orgId)) ;
		}
		sql.append("   AND TMV.AREA_ID IN ("+areaId+")\n");  
		sql.append("   AND TMV.LIFE_CYCLE = "+Constant.VEHICLE_LIFE_04+") XX\n");  
		sql.append("   WHERE (XX.IS_FLEET=10041001 AND XX.FLEET_NAME IS NOT NULL) OR XX.IS_FLEET=10041002"); 
		
		//sql.append(" ORDER BY TTS.SALES_DATE DESC\n");

//		
//			sql.append("SELECT TMD.DEALER_CODE,\n");
//			sql.append("       TMD.DEALER_SHORTNAME,\n");
//			sql.append("       DECODE(TTC.CTM_NAME, NULL, TTC.COMPANY_NAME,TTC.CTM_NAME) C_NAME, --客户名称\n");
//			sql.append("       TTC.CTM_TYPE, --客户类型\n");
//			sql.append("       TTS.IS_FLEET, --是否集团客户\n");
//			sql.append("       DECODE(TTC.CTM_NAME, NULL, TTC.COMPANY_PHONE,TTC.MAIN_PHONE) MAIN_PHONE, --主要联系电话\n");
//			sql.append("       TMVM.MATERIAL_CODE,\n");
//			sql.append("       TMVM.MATERIAL_NAME,\n");
//			sql.append("       TMV.VIN,\n");
//			sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");
//			sql.append("       TMV.VEHICLE_ID,\n");
//			sql.append("       TTC.CTM_ID\n");
//			sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");
//			sql.append("       TT_CUSTOMER            TTC,\n");
//			sql.append("       TM_VEHICLE             TMV,\n");
//			sql.append("       TM_VHCL_MATERIAL       TMVM,\n");
//			sql.append("       TM_DEALER_BUSINESS_AREA TDBA,\n");
//			sql.append("       TM_ORG              TMO,\n");
//			sql.append("       TM_DEALER_ORG_RELATION TDOR,\n");
//			sql.append("       TM_DEALER              TMD\n");
//			sql.append(" WHERE TTS.CTM_ID = TTC.CTM_ID\n");
//			sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");
//			sql.append("   AND TDBA.DEALER_ID=TMD.DEALER_ID\n");
//			sql.append("   AND TTS.DEALER_ID=TMD.DEALER_ID\n");
//			sql.append("   AND TDBA.AREA_ID=2010010100000004\n");
//			sql.append("   AND TMV.MATERIAL_ID = TMVM.MATERIAL_ID\n");
//			sql.append("AND TMO.ORG_ID=TDOR.ORG_ID AND TMD.DEALER_ID=TDOR.DEALER_ID\n");
//			sql.append("   AND TMV.LIFE_CYCLE = " + Constant.VEHICLE_LIFE_04
//							+ "\n");
//			sql.append("   AND TMD.DEALER_ID = TMV.DEALER_ID\n");
//			// 客户类型
//			if (null != orgId && !"".equals(orgId)&& !"-1".equals(orgId)) {
//				sql.append("AND TMO.ORG_CODE='"+orgId+"'\n");
//			}
//			// 客户类型
//			if (null != customer_type && !"".equals(customer_type)&& !"-1".equals(customer_type)) {
//				sql.append("   AND TTC.CTM_TYPE =" + customer_type + "\n");
//			}
//			// 客户名称
//			if (null != customer_name && !"".equals(customer_name)) {
//				sql.append("   AND (TTC.CTM_NAME LIKE '%" + customer_name.trim()+ "%' OR TTC.COMPANY_S_NAME LIKE '%" + customer_name.trim()+ "%')\n");
//			}
//			// VIN
//			if (null != vin && !"".equals(vin)) {
//				sql.append(GetVinUtil.getVins(vin, "TMV"));
//			}
//			// 状态
//			if (null != status && !"".endsWith(status) && !"-1".equals(status)) {
//				sql.append("   AND TTS.STATUS = " + status + "\n");
//			}
//			// 客户电话
//			if (null != customer_phone && !"".equals(customer_phone)) {
//				sql.append("   AND (TTC.MAIN_PHONE LIKE '%" + customer_phone.trim()+ "%' OR TTC.COMPANY_PHONE LIKE '%" + customer_phone.trim()+ "%')\n");
//			}
//			// 选择物料组
//			if (null != materialCode && !"".equals(materialCode)) {
//				String[] materialCodes = materialCode.split(",");
//				if (null != materialCodes && materialCodes.length > 0) {
//					StringBuffer buffer = new StringBuffer();
//					for (int i = 0; i < materialCodes.length; i++) {
//						buffer.append("'").append(materialCodes[i]).append("'").append(",");
//					}
//					buffer = buffer.deleteCharAt(buffer.length() - 1);
//					sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID\n");
//					sql.append("FROM TM_VHCL_MATERIAL_GROUP G \n");
//					sql.append("WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))\n");
//					sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
//					sql.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
//					sql.append("                            WHERE G.GROUP_CODE IN ("+ buffer.toString() + "))) \n");
//					sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
//					sql.append("                              FROM TM_VHCL_MATERIAL_GROUP G \n");
//					sql.append("                             WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
//				}
//			}
//			// 是否集团客户
//			if (null != is_fleet && !"".equals(is_fleet) && !"-1".equals(is_fleet)) {
//				sql.append("   AND TTS.IS_FLEET = " + is_fleet + "\n");
//			}
//
//			if (!is_fleet.equals(Constant.IF_TYPE_NO.toString())) {
//				// 集团客户名称
//				if (null != fleet_name && !"".equals(fleet_name)) {
//					sql.append("   AND TTC.COMPANY_S_NAME LIKE '%"+ fleet_name.trim() + "%'\n");
//				}
//				// 集团客户合同
//				if (null != contract_no && !"".equals(contract_no)) {
//					sql.append("   AND TTS.CONTRACT_NO LIKE '%"+ contract_no.trim() + "%'\n\n");
//				}
//			}
//			// 上报日期
//			if (null != startDate && !"".equals(startDate)) {
//				sql.append("   AND TTS.SALES_DATE >= TO_DATE('" + startDate+ "','yyyy-MM-dd')\n");
//			}
//			if (null != endDate && !"".equals(endDate)) {
//				sql.append("   AND TTS.SALES_DATE  <= (TO_DATE('" + endDate+ "','yyyy-MM-dd')+1)\n");
//			}
//
//			if (null != dealerCode && !"".equals(dealerCode)) {
//				String[] array = dealerCode.split(",");
//				sql.append("   AND TMD.DEALER_CODE IN(\n");
//				for (int i = 0; i < array.length; i++) {
//					sql.append("'" + array[i] + "'");
//					if (i != array.length - 1) {
//						sql.append(",");
//					}
//				}
//				sql.append(")\n");
//			}
//			sql.append(" ORDER BY TTS.SALES_DATE DESC\n");
		return dao.pageQuery(sql.toString(), null, dao.getFunName(), pageSize,curPage);
	}
	
	
	public List<Map<String, Object>> queryReportInfoExportList(Map<String,String> map) {
		String customer_type = (String) map.get("customer_type"); 	// 客户类型
		String customer_name = (String) map.get("customer_name"); 	// 客户名称
		String vin = (String) map.get("vin"); 						// VIN
		String customer_phone = (String) map.get("customer_phone"); // 客户电话
		String materialCode = (String) map.get("materialCode"); 	// 选择物料组
		String is_fleet = (String) map.get("is_fleet"); 			// 是否集团客户
		String fleet_name = (String) map.get("fleet_name"); 		// 集团客户名称
		String contract_no = (String) map.get("contract_no"); 		// 集团客户合同
		String startDate = (String) map.get("startDate"); 			// 上报日期:开始
		String endDate = (String) map.get("endDate"); 				// 上报日期 ：截止
		String dealerCode = (String) map.get("dealerCode"); 		// 经销商代码
		String orgCode=(String)map.get("orgCode");					// 区域
		String areaId = (String)map.get("areaId");					// 业务范围
		String orgId = map.get("orgId") ;
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT XX.DEALER_CODE,\n");
		sql.append("XX.DEALER_SHORTNAME,\n");
		sql.append("XX.CTM_NAME,\n");
		sql.append("XX.CTM_TYPE,\n");
		sql.append("XX.IS_FLEET,\n");
		sql.append("XX.FLEET_NAME,\n");
		sql.append("XX.CONTRACT_NO, \n");
		sql.append("XX.MAIN_PHONE,\n");
		sql.append("XX.MATERIAL_CODE,\n");
		sql.append("XX.MATERIAL_NAME,\n");
		sql.append("XX.VIN,\n");
		sql.append("XX.CAR_CHARACTOR,\n");
		sql.append("XX.ENGINE_NO,\n");
		sql.append("XX.PRODUCT_DATE ,\n");
		sql.append("XX.SALES_DATE,\n");
		sql.append("XX.CTM_ID,\n");
		sql.append("XX.VEHICLE_ID,\n");
		sql.append("XX.ORG_NAME,\n");
		sql.append(" XX.REGION_NAME  FROM (\n");
		sql.append("SELECT TMD.DEALER_CODE, --经销商代码\n");
		sql.append("       TMD.DEALER_SHORTNAME, --经销商名称\n"); 
		sql.append("       TMD.DEALER_ID, \n");  
		sql.append("       TTC.CTM_NAME, --客户名称\n");  
		sql.append("       TC1.CODE_DESC CTM_TYPE, --客户类型\n");  
		sql.append("       TC2.CODE_DESC IS_FLEET, --是否集团客户\n");  
		sql.append("       TF.FLEET_NAME, --集团客户名称\n");  
		sql.append("       TFC.CONTRACT_NO, --集团客户合同\n");  
		sql.append("       TTC.MAIN_PHONE, --主要联系电话\n");  
		sql.append("       M.MATERIAL_CODE, --物料代码\n");  
		sql.append("       M.MATERIAL_NAME, --物料名称\n");  
		sql.append("       TMV.VIN, --VIN\n"); 
		sql.append("TTS.CAR_CHARACTOR, --车辆性质\n");
		sql.append("       TMV.ENGINE_NO, --VIN\n"); 
		sql.append("	   TO_CHAR(TMV.PRODUCT_DATE, 'yyyy-MM-dd') PRODUCT_DATE ,\n");
		sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");  
		sql.append("       TTC.CTM_ID,\n");
		sql.append("       TMV.VEHICLE_ID,\n");
		sql.append("       VOD.ROOT_ORG_NAME ORG_NAME,VOD.REGION_NAME REGION_NAME \n");
		sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");  
		sql.append("       TM_DEALER              TMD,\n");  
		sql.append("       TT_CUSTOMER            TTC,\n");  
		sql.append("       TM_VEHICLE             TMV,\n");  
		sql.append("       TM_VHCL_MATERIAL       M,\n");  
		sql.append("       TM_FLEET               TF,\n");  
		sql.append("       TT_FLEET_CONTRACT      TFC,VW_ORG_DEALER VOD,TC_CODE TC1,TC_CODE TC2\n");  
		sql.append(" WHERE TTS.DEALER_ID = TMD.DEALER_ID\n");  
		sql.append("   AND VOD.DEALER_ID=TMD.DEALER_ID \n");
		sql.append("   AND TC1.CODE_ID = TTC.CTM_TYPE \n");
		sql.append("   AND TC2.CODE_ID = TTS.IS_FLEET");
		sql.append("   AND TTS.CTM_ID = TTC.CTM_ID\n");  
		sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");  
		sql.append("   AND TMV.MATERIAL_ID = M.MATERIAL_ID\n");  
		sql.append("   AND TTS.FLEET_ID = TF.FLEET_ID(+)\n");  
		sql.append("   AND TTS.IS_RETURN='"+Constant.IF_TYPE_NO+"'");
		sql.append("   AND TTS.CONTRACT_ID = TFC.CONTRACT_ID(+)\n");  
		if (!"".equals(customer_type)) {
			sql.append("   AND TTC.CTM_TYPE = "+customer_type+"\n");
		}
		if (!"".equals(customer_name)) {
			sql.append("   AND TTC.CTM_NAME LIKE '%"+customer_name.trim()+"%'\n");
		}
		if (!"".equals(vin)) {
			sql.append(GetVinUtil.getVins(vin, "TMV"));
		}
		if (!"".equals(customer_phone)) {
			sql.append("   AND TTC.MAIN_PHONE LIKE '%"+customer_phone.trim()+"%'\n");
		}
		if (null != materialCode && !"".equals(materialCode)) {
			String[] materialCodes = materialCode.split(",");
			if (null != materialCodes && materialCodes.length > 0) {
				StringBuffer buffer = new StringBuffer();
				for (int i = 0; i < materialCodes.length; i++) {
					buffer.append("'").append(materialCodes[i]).append("'").append(",");
				}
				buffer = buffer.deleteCharAt(buffer.length() - 1);
				sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID\n");
				sql.append("FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))\n");
				sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                            WHERE G.GROUP_CODE IN ("+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                              FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                             WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
			}
		}
		if (!"".equals(is_fleet)) {
			sql.append("   AND TTS.IS_FLEET = "+is_fleet+"\n");
		}
		if (!"".equals(fleet_name)) {
			sql.append("   AND TF.FLEET_NAME LIKE '%"+fleet_name+"%'\n");
		}
		if (!"".equals(contract_no)) {
			sql.append("   AND TFC.CONTRACT_NO LIKE '%"+contract_no+"%'\n");
		}
		if (null != startDate && !"".equals(startDate)) {
			sql.append("   AND TTS.SALES_DATE >= TO_DATE('"+ startDate+" 00:00:00','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != endDate && !"".equals(endDate)) {
			sql.append("   AND TTS.SALES_DATE  <= TO_DATE('"+endDate+" 23:59:59','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != dealerCode && !"".equals(dealerCode)) {
			String[] array = dealerCode.split(",");
			sql.append("   AND TMD.DEALER_CODE IN(\n");
			for (int i = 0; i < array.length; i++) {
				sql.append("'" + array[i] + "'");
				if (i != array.length - 1) {
					sql.append(",");
				}
			}
			sql.append(")\n");
		}
		if (!"".equals(orgCode)) {
			sql.append("AND TMD.DEALER_ID IN\n");
			sql.append("       (SELECT TD.DEALER_ID\n");  
			sql.append("          FROM TM_DEALER TD\n");  
			sql.append("         START WITH TD.DEALER_ID IN\n");  
			sql.append("                    (SELECT TDOR.DEALER_ID\n");  
			sql.append("                       FROM TM_DEALER_ORG_RELATION TDOR\n");  
			sql.append("                      WHERE TDOR.ORG_ID IN\n");  
			sql.append("                            (SELECT ORG_ID\n");  
			sql.append("                               FROM TM_ORG ORG\n");  
			sql.append("                              WHERE ORG.STATUS = "+Constant.STATUS_ENABLE+"\n");  
			sql.append("                              START WITH ORG_CODE = '"+orgCode+"'\n");  
			sql.append("                             CONNECT BY PRIOR ORG.ORG_ID = ORG.PARENT_ORG_ID))\n");  
			sql.append("        CONNECT BY PRIOR TD.DEALER_ID = TD.PARENT_DEALER_D)\n");

		}
		
		if(!CommonUtils.isNullString(orgId)) {
			sql.append(ReqQueryDao.limitOrg("TMD", "dealer_id", orgId)) ;
		}
		
		sql.append("   AND TMV.AREA_ID IN ("+areaId+")\n");  
		sql.append("   AND TMV.LIFE_CYCLE = "+Constant.VEHICLE_LIFE_04+"\n");  
		sql.append(" UNION \n");
		sql.append("SELECT TMD.DEALER_CODE, --经销商代码\n");
		sql.append("       TMD.DEALER_SHORTNAME, --经销商名称\n"); 
		sql.append("       TMD.DEALER_ID, \n");  
		sql.append("       TTC.CTM_NAME, --客户名称\n");  
		sql.append("       TC1.CODE_DESC CTM_TYPE, --客户类型\n");  
		sql.append("       TC2.CODE_DESC IS_FLEET, --是否集团客户\n");  
		sql.append("       TCP.PACT_NAME FLEET_NAME, --集团客户名称\n");  
		sql.append("       TCP.PACT_NAME CONTRACT_NO, --集团客户合同\n");  
		sql.append("       TTC.MAIN_PHONE, --主要联系电话\n");  
		sql.append("       M.MATERIAL_CODE, --物料代码\n");  
		sql.append("       M.MATERIAL_NAME, --物料名称\n");  
		sql.append("       TMV.VIN, --VIN\n"); 
		sql.append("TTS.CAR_CHARACTOR, --车辆性质\n");
		sql.append("       TMV.ENGINE_NO, --VIN\n"); 
		sql.append("	   TO_CHAR(TMV.PRODUCT_DATE, 'yyyy-MM-dd') PRODUCT_DATE ,\n");
		sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");  
		sql.append("       TTC.CTM_ID,\n");
		sql.append("       TMV.VEHICLE_ID,\n");
		sql.append("       VOD.ROOT_ORG_NAME ORG_NAME,VOD.REGION_NAME REGION_NAME \n");
		sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");  
		sql.append("       TM_DEALER              TMD,\n");  
		sql.append("       TT_CUSTOMER            TTC,\n");  
		sql.append("       TM_VEHICLE             TMV,\n");  
		sql.append("       TM_VHCL_MATERIAL       M,\n");  
		sql.append("       TM_FLEET               TF,\n");  
		sql.append("       TT_FLEET_CONTRACT      TFC,TM_COMPANY_PACT TCP,VW_ORG_DEALER VOD,TC_CODE TC1,TC_CODE TC2\n");  
		sql.append(" WHERE TTS.DEALER_ID = TMD.DEALER_ID\n");  
		sql.append("   AND TC1.CODE_ID = TTC.CTM_TYPE \n");
		sql.append("   AND TC2.CODE_ID = TTS.IS_FLEET");
		sql.append("   AND VOD.DEALER_ID=TMD.DEALER_ID \n");
		sql.append("   AND TTS.CTM_ID = TTC.CTM_ID\n");  
		sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");  
		sql.append("   AND TMV.MATERIAL_ID = M.MATERIAL_ID\n");  
		sql.append("   AND TTS.FLEET_ID = TCP.PACT_ID\n");  
		sql.append("   AND TTS.IS_RETURN='"+Constant.IF_TYPE_NO+"'");
		sql.append("   AND TTS.CONTRACT_ID = TFC.CONTRACT_ID(+)\n");  
		if (!"".equals(customer_type)) {
			sql.append("   AND TTC.CTM_TYPE = "+customer_type+"\n");
		}
		if (!"".equals(customer_name)) {
			sql.append("   AND TTC.CTM_NAME LIKE '%"+customer_name.trim()+"%'\n");
		}
		if (!"".equals(vin)) {
			sql.append(GetVinUtil.getVins(vin, "TMV"));
		}
		if (!"".equals(customer_phone)) {
			sql.append("   AND TTC.MAIN_PHONE LIKE '%"+customer_phone.trim()+"%'\n");
		}
		if (null != materialCode && !"".equals(materialCode)) {
			String[] materialCodes = materialCode.split(",");
			if (null != materialCodes && materialCodes.length > 0) {
				StringBuffer buffer = new StringBuffer();
				for (int i = 0; i < materialCodes.length; i++) {
					buffer.append("'").append(materialCodes[i]).append("'").append(",");
				}
				buffer = buffer.deleteCharAt(buffer.length() - 1);
				sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID\n");
				sql.append("FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))\n");
				sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                            WHERE G.GROUP_CODE IN ("+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
				sql.append("                              FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append("                             WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
			}
		}
		if (!"".equals(is_fleet)) {
			sql.append("   AND TTS.IS_FLEET = "+is_fleet+"\n");
		}
		if (!"".equals(fleet_name)) {
			sql.append("   AND TF.FLEET_NAME LIKE '%"+fleet_name+"%'\n");
		}
		if (!"".equals(contract_no)) {
			sql.append("   AND TFC.CONTRACT_NO LIKE '%"+contract_no+"%'\n");
		}
		if (null != startDate && !"".equals(startDate)) {
			sql.append("   AND TTS.SALES_DATE >= TO_DATE('"+ startDate+" 00:00:00','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != endDate && !"".equals(endDate)) {
			sql.append("   AND TTS.SALES_DATE  <= TO_DATE('"+endDate+" 23:59:59','yyyy-MM-dd HH24:MI:SS')\n");
		}
		if (null != dealerCode && !"".equals(dealerCode)) {
			String[] array = dealerCode.split(",");
			sql.append("   AND TMD.DEALER_CODE IN(\n");
			for (int i = 0; i < array.length; i++) {
				sql.append("'" + array[i] + "'");
				if (i != array.length - 1) {
					sql.append(",");
				}
			}
			sql.append(")\n");
		}
		if (!"".equals(orgCode)) {
			sql.append("AND TMD.DEALER_ID IN\n");
			sql.append("       (SELECT TD.DEALER_ID\n");  
			sql.append("          FROM TM_DEALER TD\n");  
			sql.append("         START WITH TD.DEALER_ID IN\n");  
			sql.append("                    (SELECT TDOR.DEALER_ID\n");  
			sql.append("                       FROM TM_DEALER_ORG_RELATION TDOR\n");  
			sql.append("                      WHERE TDOR.ORG_ID IN\n");  
			sql.append("                            (SELECT ORG_ID\n");  
			sql.append("                               FROM TM_ORG ORG\n");  
			sql.append("                              WHERE ORG.STATUS = "+Constant.STATUS_ENABLE+"\n");  
			sql.append("                              START WITH ORG_CODE = '"+orgCode+"'\n");  
			sql.append("                             CONNECT BY PRIOR ORG.ORG_ID = ORG.PARENT_ORG_ID))\n");  
			sql.append("        CONNECT BY PRIOR TD.DEALER_ID = TD.PARENT_DEALER_D)\n");

		}
		
		if(!CommonUtils.isNullString(orgId)) {
			sql.append(ReqQueryDao.limitOrg("TMD", "dealer_id", orgId)) ;
		}
		
		sql.append("   AND TMV.AREA_ID IN ("+areaId+")\n");  
		sql.append("   AND TMV.LIFE_CYCLE = "+Constant.VEHICLE_LIFE_04+") XX\n");  
		sql.append("   WHERE (XX.IS_FLEET='是' AND XX.FLEET_NAME IS NOT NULL) OR XX.IS_FLEET='否'");
		
		return dao.pageQuery(sql.toString(), null, dao.getFunName());
	}

	public static List<Map<String, Object>> getOemCalDetailExportList(Map map) {
		String customer_type = (String) map.get("customer_type"); // 客户类型
		String customer_name = (String) map.get("customer_name"); // 客户名称
		String vin = (String) map.get("vin"); // VIN
		String customer_phone = (String) map.get("customer_phone"); // 客户电话
		String materialCode = (String) map.get("materialCode"); // 选择物料组
		String is_fleet = (String) map.get("is_fleet"); // 是否大客户
		String fleet_name = (String) map.get("fleet_name"); // 大客户名称
		String contract_no = (String) map.get("contract_no"); // 大客户合同
		String startDate = (String) map.get("startDate"); // 上报日期:开始
		String endDate = (String) map.get("endDate"); // 上报日期 ：截止
		String dealerCode = (String) map.get("dealerCode"); // 经销商代码

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT TMD.DEALER_CODE,\n");
		sql.append("       TMD.DEALER_SHORTNAME,\n");
		sql.append("       DECODE(TTC.CTM_NAME, NULL, TTC.COMPANY_S_NAME,TTC.CTM_NAME) C_NAME, --客户名称\n");
		sql.append("       TTC.CTM_TYPE, --客户类型\n");
		sql.append("       TTS.IS_FLEET, --是否大客户\n");
		sql.append("       DECODE(TTC.CTM_NAME, NULL, TTC.COMPANY_PHONE, TTC.MAIN_PHONE) MAIN_PHONE, --主要联系电话\n");
		sql.append("       TMVM.MATERIAL_CODE,\n");
		sql.append("       TMVM.MATERIAL_NAME,\n");
		sql.append("       TMV.VIN,\n");
		sql.append("       TO_CHAR(TTS.SALES_DATE, 'yyyy-MM-dd') SALES_DATE, --实销时间\n");
		sql.append("       TMV.VEHICLE_ID,\n");
		sql.append("       TTC.CTM_ID\n");
		sql.append("  FROM TT_DEALER_ACTUAL_SALES TTS,\n");
		sql.append("       TT_CUSTOMER            TTC,\n");
		sql.append("       TM_VEHICLE             TMV,\n");
		sql.append("       TM_VHCL_MATERIAL       TMVM,\n");
		sql.append("       TM_DEALER              TMD\n");

		sql.append(" WHERE TTS.CTM_ID = TTC.CTM_ID\n");
		sql.append("   AND TTS.VEHICLE_ID = TMV.VEHICLE_ID\n");
		sql.append("   AND TMV.MATERIAL_ID = TMVM.MATERIAL_ID\n");
		sql.append("   AND TMV.LIFE_CYCLE = " + Constant.VEHICLE_LIFE_04
						+ "\n");
		sql.append("   AND TMD.DEALER_ID = TMV.DEALER_ID\n");

		// 客户类型
		if (null != customer_type && !"".equals(customer_type)
				&& !"-1".equals(customer_type)) {
			sql.append("   AND TTC.CTM_TYPE =" + customer_type + "\n");
		}
		// 客户名称
		if (null != customer_name && !"".equals(customer_name)) {
			sql.append("   AND (TTC.CTM_NAME LIKE '%" + customer_name.trim()
					+ "%' OR TTC.COMPANY_S_NAME LIKE '%" + 

customer_name.trim()
					+ "%')\n");
		}
		// VIN
		if (null != vin && !"".equals(vin)) {
			sql.append(GetVinUtil.getVins(vin, "TMV"));
		}
		// 客户电话
		if (null != customer_phone && !"".equals(customer_phone)) {
			sql.append("   AND (TTC.MAIN_PHONE LIKE '%" + customer_phone.trim

()
					+ "%' OR TTC.COMPANY_PHONE LIKE '%" + 

customer_phone.trim()
					+ "%')\n");
		}
		// 选择物料组
		if (null != materialCode && !"".equals(materialCode)) {
			String[] materialCodes = materialCode.split(",");
			if (null != materialCodes && materialCodes.length > 0) {
				StringBuffer buffer = new StringBuffer();
				for (int i = 0; i < materialCodes.length; i++) {
					buffer.append("'").append(materialCodes

[i]).append("'")
							.append(",");
				}
				buffer = buffer.deleteCharAt(buffer.length() - 1);
				sql.append("   AND ((TMV.PACKAGE_ID IN (SELECT G.GROUP_ID \n");
				sql
						.append("                               FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql
						.append("                 WHERE G.GROUP_CODE IN ("
								+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.MODEL_ID IN (SELECT G.GROUP_ID \n");
				sql
						.append("                             FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql
						.append("                            WHERE G.GROUP_CODE IN ("							+ buffer.toString() + "))) \n");
				sql.append("       OR (TMV.SERIES_ID IN (SELECT G.GROUP_ID \n");
				sql
						.append("                        FROM TM_VHCL_MATERIAL_GROUP G \n");
				sql.append(" WHERE G.GROUP_CODE IN ("+ buffer.toString() + ")))) \n");
			}
		}
		// 是否大客户
		if (null != is_fleet && !"".equals(is_fleet) && !"-1".equals(is_fleet)) {
			sql.append("   AND TTS.IS_FLEET = " + is_fleet + "\n");
		}

		if (!is_fleet.equals(Constant.IF_TYPE_NO.toString())) {
			// 大客户名称
			if (null != fleet_name && !"".equals(fleet_name)) {
				sql.append("   AND TTC.COMPANY_S_NAME LIKE '%"
						+ fleet_name.trim() + "%'\n");
			}
			// 大客户合同
			if (null != contract_no && !"".equals(contract_no)) {
				sql.append("   AND TTS.CONTRACT_NO LIKE '%"
						+ contract_no.trim() + "%'\n\n");
			}
		}
		// 上报日期
		if (null != startDate && !"".equals(startDate)) {
			sql.append("   AND TTS.SALES_DATE >= TO_DATE('" + startDate
					+ "','yyyy-MM-dd')\n");
		}
		if (null != endDate && !"".equals(endDate)) {
			sql.append("   AND TTS.SALES_DATE  <= (TO_DATE('" + endDate
					+ "','yyyy-MM-dd')+1)\n");
		}

		if (null != dealerCode && !"".equals(dealerCode)) {
			String[] array = dealerCode.split(",");
			sql.append("   AND TMD.DEALER_CODE IN(\n");
			for (int i = 0; i < array.length; i++) {
				sql.append("'" + array[i] + "'");
				if (i != array.length - 1) {
					sql.append(",");
				}
			}
			sql.append(")\n");
		}
		sql.append(" ORDER BY TTS.SALES_DATE DESC\n");
		List<Map<String, Object>> list=dao.pageQuery(sql.toString(), null, 

dao.getFunName());
		return  list;
	}
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}

}